package com.zzyl.generator.util;

import com.zzyl.common.constant.Constants;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;

import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;

public class VelocityDemoTest {
    public static void main (String[] args) throws IOException {
        Properties p=new Properties();
        p.setProperty("resource.loader.file.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
        p.setProperty(Velocity.INPUT_ENCODING, Constants.UTF8);
        Velocity.init(p);

        VelocityContext context=new VelocityContext();
        context.put("message","超级赛亚人");
        Template template=Velocity.getTemplate("vms/index.html.vm","UTF-8");
        //输出
        FileWriter fileWriter=new FileWriter("D:\\P\\index.html");
        template.merge(context,fileWriter);
        fileWriter.close();
    }
}
